home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
dirut
/
djm_size.zip
/
SIZE.C
< prev
next >
Wrap
Text File
|
1989-08-07
|
2KB
|
74 lines
/* Program SIZE
D.J. Murphy August 1989
Used as a pipe for the DOS DIR command in full list (i.e. not using
either the /W or /P switches) mode to report total directory size.
Usage: DIR [d:\path]|SIZE [/N]
Prints directory listing, then size report afterwards, unless /N switch
selected, in which case size only is reported.
DIR reports file sizes in columns 14-21 inclusive of the resultant list.
Turbo C v1.5 compile options: No FP
Tiny memory model
Register variables
optimize for size
*/
/************ HEADERS *****************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/************ DEFINES *****************/
#define COLSTART 13
#define COLEND 20
#define REJECT "<DIR>" /* disregard lines with this */
#define TRMNT "bytes free" /* last line */
/**************************************/
main(argc, argv)
int argc;
char *argv[];
{
char line[40]; /* Readin line and file size */
unsigned long int sum, factor;
int ccount, lcount;
int eflag = 0; /* End flag */
sum = 0;
ccount = lcount = 0;
do {
gets(line);
lcount++;
if (lcount > 4) {
if (!strstr(line,TRMNT)) { /* "bytes free" not found */
if (!strstr(line,REJECT)) { /* "<DIR>" not found */
factor = 1;
for (ccount = COLEND; ccount >= COLSTART; ccount--) {
if (line[ccount] != ' ') {
sum += ((line[ccount] - '0') * factor);
factor *= 10;
} else
ccount = COLSTART - 1;
}
}
} else
eflag = 1;
}
if (argc == 1)
printf("%s\n", line);
} while(!eflag);
printf("\nDirectory size %lu bytes\n", sum);
}